% -------------------------------------------------------------------------
% 构造目标函数
%
% Copyright(C) 2015/04/29 by Chen Zhang, 
% School of Astronautics, Beihang University
% chenzhang.buaa@gmail.com
% -------------------------------------------------------------------------
function [f , g] = obj(xx , auxdata)
mu = auxdata.mu;
ri = auxdata.ri;
rf = auxdata.rf;
xi = xx(1); yi = xx(2); vxi = xx(3); vyi = xx(4); ti = xx(5); tf = xx(6);
xxi = [xi; yi; vxi; vyi];
% 四体动力学积分
options = odeset('AbsTol' , 1e-8 , 'RelTol' , 1e-8);
[~ , xxf] = ode113(@f4y , [ti , tf] , [xxi] , options , auxdata);
xf = xxf(end , 1); yf = xxf(end , 2);
vxf = xxf(end , 3); vyf = xxf(end , 4);
% 计算初始脉冲和终端脉冲
dvi = sqrt((vxi - yi)^2 + (vyi + xi + mu)^2) - sqrt((1 - mu) / ri);
dvf = sqrt((vxf - yf)^2 + (vyf + xf + mu - 1)^2) - sqrt(mu / rf);
f = dvi + dvf;
g = [];
end
